package com.study.forewarn.service.impl;// com.study.forewarn.service.impl.ForewarnServiceImpl
import com.study.course.mapper.SysCourseMapper;
import com.study.forewarn.domain.AcademicWarning;
import com.study.forewarn.domain.CombinedWarningVO;
import com.study.forewarn.mapper.AcademicWarningRepository;
import com.study.forewarn.service.ForewarnService;
import com.study.student.domain.SysStudent;
import com.study.course.domain.SysCourse;

import com.study.student.mapper.SysStudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class ForewarnServiceImpl implements ForewarnService {

    @Autowired
    private AcademicWarningRepository academicWarningRepository;

    @Autowired
    private SysStudentMapper sysStudentMapper;

    @Autowired
    private SysCourseMapper sysCourseMapper;

    @Override
    public List<CombinedWarningVO> getCombinedWarningList() {
        List<AcademicWarning> warnings = academicWarningRepository.findAll();

        return warnings.stream().map(warning -> {
            // warning.getStudentName() 其实是 studentId
            SysStudent student = sysStudentMapper.selectSysStudentByStudentId(warning.getStudentName());
            SysCourse course = sysCourseMapper.selectSysCourseByCourseId(warning.getCourseName());

            CombinedWarningVO vo = new CombinedWarningVO();
            vo.setStudentName(student != null ? student.getName() : "未知学生");
            vo.setCourseName(course != null ? course.getCourseName() : "未知课程");
            vo.setScore(warning.getScore());

            return vo;
        }).collect(Collectors.toList());
    }
}
